Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support canonical ledger entry names #5271

Merged
merged 5 commits into from
Feb 14, 2025
Merged

Conversation

bthomee
Copy link
Collaborator

@bthomee bthomee commented Feb 1, 2025

High Level Overview of Change

This change implements #4393, which enhances the filtering in the ledger, ledger_data, and account_objects methods by also supporting filtering by the canonical name of the LedgerEntryType using case-insensitive matching.

Context of Change

Currently the mapping between the RPC name to provide as filter and the LedgerEntryType is inconsistent and sometimes surprising. For example, to match the DirectoryNode the provided RPC name is directory, while for PayChannel it is payment_channel.

This change enables filtering on the canonical name as well to make the mapping consistent and unsurprising. For instance, to filter on PayChannel it is still possible to specify payment_channel, but now it's also possible to specify PayChannel and paychannel (or any variant thereof using different casing).

Type of Change

  • New feature (non-breaking change which adds functionality)

API Impact

  • Public API: New feature (new methods and/or new fields)

Before / After

See #4393 for an excellent description.

Copy link

codecov bot commented Feb 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.2%. Comparing base (dc9e6c3) to head (7a35881).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #5271   +/-   ##
=======================================
  Coverage     78.1%   78.2%           
=======================================
  Files          790     790           
  Lines        67652   67652           
  Branches      8165    8165           
=======================================
+ Hits         52870   52874    +4     
+ Misses       14782   14778    -4     
Files with missing lines Coverage Δ
src/xrpld/rpc/detail/RPCHelpers.cpp 82.8% <100.0%> (ø)

... and 3 files with indirect coverage changes

Impacted file tree graph

@mvadari
Copy link
Collaborator

mvadari commented Feb 3, 2025

Why deprecate the old filter names? Why not support both?

@bthomee
Copy link
Collaborator Author

bthomee commented Feb 3, 2025

Why deprecate the old filter names? Why not support both?

@mDuo13 can you respond? In the issue you had raised you mentioned "For backwards compatibility, continue to also support the existing short names (but mark them deprecated in the documentation)." - are there requests from the community to deprecate that field to reduce confusion, or is there another reason?

@mDuo13
Copy link
Collaborator

mDuo13 commented Feb 3, 2025

The reason to mark it deprecated is so that we can move away from needing a short name for new ledger entries (a dev task that was often forgotten in the past anyway). There should be one preferred way to look up ledger entry types, by their canonical name (case-insensitive).

It's fine if the existing, "deprecated" shortcut names are supported indefinitely too.

@bthomee bthomee requested a review from godexsoft February 4, 2025 18:18
@mvadari
Copy link
Collaborator

mvadari commented Feb 5, 2025

Maybe this is an unpopular opinion but I actually like the lower-case names, and think we should keep them.

note: I have no objection to adding additional filter names, just to deprecating/replacing the existing setup.

@bthomee
Copy link
Collaborator Author

bthomee commented Feb 5, 2025

Maybe this is an unpopular opinion but I actually like the lower-case names, and think we should keep them.

note: I have no objection to adding additional filter names, just to deprecating/replacing the existing setup.

I have no particular opinion here or sufficient background to know how people use this API, but do note that this PR explicitly adds support for case-insensitive filtering; so lowercase names are definitely possible.

Copy link
Collaborator

@godexsoft godexsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just leaving a suggestion. Looks good overall 👍

static constexpr auto types =
std::to_array<std::pair<char const*, LedgerEntryType>>({
static constexpr auto types = std::to_array<
std::tuple<char const*, char const*, LedgerEntryType>>({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: For readability, consider a small struct instead of the tuple.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured that if we're going to deprecate the current way of referencing ledger entries, then the next release we can return to using a std::pair - which would be preferred over a dedicated struct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the RPC name-based deprecation is no longer going to happen, I looked at this again and think that adding a new struct just for this function is overkill, however small that struct may be.

@bthomee
Copy link
Collaborator Author

bthomee commented Feb 7, 2025

Maybe this is an unpopular opinion but I actually like the lower-case names, and think we should keep them.
note: I have no objection to adding additional filter names, just to deprecating/replacing the existing setup.

I have no particular opinion here or sufficient background to know how people use this API, but do note that this PR explicitly adds support for case-insensitive filtering; so lowercase names are definitely possible.

@mDuo13 & @mvadari, let's discuss whether or not to deprecate the existing setup. In particular, @mDuo13 raised some good points, so @mvadari do you feel strongly about that we should keep the existing, frequently odd, naming convention & the increased burden in remembering to add such a separate name for each new ledger entry type?

@mvadari
Copy link
Collaborator

mvadari commented Feb 7, 2025

Maybe this is an unpopular opinion but I actually like the lower-case names, and think we should keep them.
note: I have no objection to adding additional filter names, just to deprecating/replacing the existing setup.

I have no particular opinion here or sufficient background to know how people use this API, but do note that this PR explicitly adds support for case-insensitive filtering; so lowercase names are definitely possible.

@mDuo13 & @mvadari, let's discuss whether or not to deprecate the existing setup. In particular, @mDuo13 raised some good points, so @mvadari do you feel strongly about that we should keep the existing, frequently odd, naming convention & the increased burden in remembering to add such a separate name for each new ledger entry type?

The rpcName got added to the ledger entry macro in #5202, so that should make it much easier to keep everything aligned.

@ximinez
Copy link
Collaborator

ximinez commented Feb 10, 2025

IMHO, the way forward here is to preserve the backward compatibility on the existing "short names" indefinitely, but deprecate adding new ones, or at least making it optional.

Instead of marking anything deprecated, the documentation could, for example, include a list of values that can be used to query each type, and as we add new types, only include the canonical name.

Copy link
Collaborator

@intelliot intelliot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using existing public Devnet servers, I would get:

RippledError: Invalid field 'type'.
{
  data: {
    api_version: 2,
    error: 'invalidParams',
    error_code: 31,
    error_message: "Invalid field 'type'.",
    id: 2,
    request: {
      api_version: 2,
      command: 'ledger_data',
      id: 2,
      type: 'MPTokenIssuance'
    },
    status: 'error',
    type: 'response'
  }
}

I compiled and ran this PR on Devnet. The same query works great! 👍

Thank you for this!

@bthomee
Copy link
Collaborator Author

bthomee commented Feb 11, 2025

When using existing public Devnet servers, I would get:

RippledError: Invalid field 'type'.
{
  data: {
    api_version: 2,
    error: 'invalidParams',
    error_code: 31,
    error_message: "Invalid field 'type'.",
    id: 2,
    request: {
      api_version: 2,
      command: 'ledger_data',
      id: 2,
      type: 'MPTokenIssuance'
    },
    status: 'error',
    type: 'response'
  }
}

I compiled and ran this PR on Devnet. The same query works great! 👍

Thank you for this!

Great to hear! I'll follow @ximinez's and @mvadari's suggestions to keep this backward compatible, and will make changes accordingly soon.

@bthomee
Copy link
Collaborator Author

bthomee commented Feb 12, 2025

IMHO, the way forward here is to preserve the backward compatibility on the existing "short names" indefinitely, but deprecate adding new ones, or at least making it optional.

Instead of marking anything deprecated, the documentation could, for example, include a list of values that can be used to query each type, and as we add new types, only include the canonical name.

I've removed the deprecation notices. In terms of the documentation, while it can be added to the code here, I think it would be better to have the possible ledger entry values documented in the various libraries that contact rippled over RPC.

@bthomee bthomee added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Feb 12, 2025
@bthomee bthomee merged commit 7c9d652 into develop Feb 14, 2025
24 checks passed
@bthomee bthomee deleted the bthomee/ledgertypefilter branch February 14, 2025 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants